package com.example.service.impl;

import com.example.mapper.fixtureTechConditionMapp;
import com.example.pojo.fixtureListPojo;
import com.example.pojo.fixtureTechConditionPojo;
import com.example.service.fixtureListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Service
public class fixtureListImpl implements fixtureListService {
    @Autowired
    private com.example.mapper.fixtureListMapp fixtureListMapp;
    //insertOne方法接收一个fixtureListPojo对象作为参数，执行插入操作后，不返回任何结果（void）
    public void insertOne(fixtureListPojo pojo){
        //定义创建时间生成规则
        pojo.setCreate_time(LocalDateTime.now());
        //定义修改时间生成规则
        pojo.setUpdate_time(LocalDateTime.now());
        //调用 Mapper 插入数据
        fixtureListMapp.insertOne(pojo);
    };

    //查询工装技术条件中所有的数据
    public List<fixtureListPojo> queryAll(){
        //调用fixtureListMapp.queryAll()方法，将查询结果存储在pojoList变量中
        List<fixtureListPojo> pojoList = fixtureListMapp.queryAll();
        //直接返回从Mapper获取的结果列表
        return pojoList;
    };

    //根据ID，选择一行数据
    public fixtureListPojo selectById(String id){
        fixtureListPojo pojo=fixtureListMapp.selectById(id);
        return pojo;
    }

    //根据IdUse编辑某一行数据
    public void editOneById(fixtureListPojo pojo){
        //定义修改时间生成规则
        pojo.setUpdate_time(LocalDateTime.now());
        //调用 Mapper 编辑数据
        fixtureListMapp.editOneByIdUse(pojo);
    }

    //查询某一字段为某值的数据
    public List<fixtureListPojo> queryOneField(Map<String, Object> map){
        String fieldName = map.get("fieldName").toString();
        String fieldValue = map.get("fieldVal").toString();
        List<fixtureListPojo> fixtureListPojos=fixtureListMapp.queryOneField(fieldName, fieldValue);
        return fixtureListPojos;
    }

    //对一个字段，从老值更改为新值
    public void editByField(String fieldName, String old, String newData){
        fixtureListMapp.editByField(fieldName,old,newData);
    }
}
